<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Api\BaseController;
use Illuminate\Http\Request;
use App\Model\OperationLogs;
use App\Model\HopeLuck;

class HopeLuckController extends BaseController
{
    protected $model = null;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->model = new HopeLuck();
    }

    //许愿池设置单次抽奖消耗数量
    public function wishLuckSetNeedNum(Request $request){
        $res = $this->model->wishLuckSetNeedNum($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池设置单次抽奖消耗数量');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池设置档位抽取次数
    public function wishLuckSetDrawNum(Request $request){
        $res = $this->model->wishLuckSetDrawNum($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池设置档位抽取次数');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池设置奖池开启/关闭
    public function wishLuckSetPoolStatus(Request $request){
        $res = $this->model->wishLuckSetPoolStatus($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池设置奖池开启/关闭');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池保存奖池配置
    public function wishLuckSavePoolConfig(Request $request){
        $res = $this->model->wishLuckSavePoolConfig($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池保存奖池配置');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池新增奖池
    public function wishLuckAddPool(Request $request){
        $res = $this->model->wishLuckAddPool($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池新增奖池');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池编辑奖池
    public function wishLuckEditPool(Request $request){
        $res = $this->model->wishLuckEditPool($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池编辑奖池');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池更新奖池缓存
    public function wishLuckPoolReset(Request $request){
        $res = $this->model->wishLuckPoolReset($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池更新奖池缓存');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖池列表
    public function wishLuckPoolList(Request $request){
        $res = $this->model->wishLuckPoolList($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池配置信息
    public function wishLuckConfig(Request $request){
        $res = $this->model->wishLuckConfig($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖池配置列表
    public function wishLuckPoolConfigList(Request $request){
        $res = $this->model->wishLuckPoolConfigList($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖池配置剩余数量
    public function wishLuckPoolConfigNum(Request $request){
        $res = $this->model->wishLuckPoolConfigNum($request->all());
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池新增白名单
    public function wishLuckAddWhite(Request $request){
        $res = $this->model->wishLuckAddWhite($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池新增白名单');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池删除白名单
    public function wishLuckDelWhite(Request $request){
        $res = $this->model->wishLuckDelWhite($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池删除白名单');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池白名单列表
    public function wishLuckWhiteList(Request $request){
        $res = $this->model->wishLuckWhiteList($request, $this->user);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池抽奖明细列表
    public function wishLuckDrawList(Request $request){
        $res = $this->model->wishLuckDrawList($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池抽奖用户汇总数据
    public function wishLuckUserStatistic(Request $request){
        $res = $this->model->wishLuckUserStatistic($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池抽奖用户汇总数据(同设备查询)
    public function childWishLuckUserStatistic(Request $request){
        $res = $this->model->childWishLuckUserStatistic($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池抽奖每日统计
    public function wishLuckDayStatistic(Request $request){
        $res = $this->model->wishLuckDayStatistic($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池新增展示礼物
    public function wishLuckAddGift(Request $request){
        $res = $this->model->wishLuckAddGift($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池新增展示礼物');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池删除展示礼物
    public function wishLuckDelGift(Request $request){
        $res = $this->model->wishLuckDelGift($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池删除展示礼物');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖品列表
    public function wishLuckGiftList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->wishLuckGiftList($request));
    }

    //许愿池新增个人池用户
    public function wishLuckAddPoolUser(Request $request){
        $res = $this->model->wishLuckAddPoolUser($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池新增个人池用户');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池删除个人池用户
    public function wishLuckDelPoolUser(Request $request){
        $res = $this->model->wishLuckDelPoolUser($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池删除个人池用户');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池查看个人奖池剩余数
    public function wishLuckPoolSelfConfigNum(Request $request){
        $res = $this->model->wishLuckPoolSelfConfigNum($request->all());

        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池个人池用户列表
    public function wishLuckPoolUserList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->wishLuckPoolUserList($request));
    }

    //许愿池奖池已配置礼物列表
    public function wishLuckPoolGift(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->wishLuckPoolGift($request));
    }

    //许愿池新增奖池白名单
    public function wishLuckAddPoolWhite(Request $request){
        $res = $this->model->wishLuckAddPoolWhite($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池新增奖池白名单');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池删除奖池白名单
    public function wishLuckDelPoolWhite(Request $request){
        $res = $this->model->wishLuckDelPoolWhite($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池删除奖池白名单');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池取消投放奖池白名单
    public function wishLuckCancelPoolWhite(Request $request){
        $res = $this->model->wishLuckCancelPoolWhite($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池取消投放奖池白名单');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖池白名单列表
    public function wishLuckPoolWhiteList(Request $request){
        $res = $this->model->wishLuckPoolWhiteList($request, $this->user);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池个人池奖池列表
    public function wishLuckUserPoolList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->wishLuckUserPoolList($request));
    }

    //许愿池更新进入个人池配置
    public function wishLuckSetInUserPoolConfig(Request $request){
        $res = $this->model->wishLuckSetInUserPoolConfig($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池更新进入个人池配置');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池更新离开个人池配置
    public function wishLuckSetOutUserPoolConfig(Request $request){
        $res = $this->model->wishLuckSetOutUserPoolConfig($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池更新离开个人池配置');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池个人池汇总数据
    public function wishLuckUserPoolStat(Request $request){
        $res = $this->model->wishLuckUserPoolStat($request);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池奖池更新阀值
    public function wishLuckSetUserPoolConfig(Request $request){
        $res = $this->model->wishLuckSetUserPoolConfig($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '许愿池奖池更新阀值');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池获取特殊礼物配置(五动乾坤,神秘珍宝)
    public function wishLuckPoolConfigChildList(Request $request){
        $pool_id = $request->get('pool_id',0);//奖池id
        $gift_id = $request->get('gift_id',0);//奖池礼物id
        $pool_config_id = $request->get('pool_config_id',0);//奖池配置id
        if(empty($pool_id) || empty($gift_id) || empty($pool_config_id)){
            return $this->toJson(self::PARAM_ERROR);
        }
        $res = $this->model->wishLuckPoolConfigChildList($pool_id, $gift_id, $pool_config_id);
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池特殊玩法配置
    public function wishLuckPoolConfigChildAdd(Request $request){
        $res = $this->model->wishLuckPoolConfigChildAdd($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '新增许愿池奖池配置特殊玩法');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //编辑特殊玩法配置
    public function wishLuckPoolConfigChildEdit(Request $request){
        $res = $this->model->wishLuckPoolConfigChildEdit($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '编辑许愿池奖池配置特殊玩法');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //删除特殊玩法配置
    public function wishLuckPoolConfigChildDel(Request $request){
        $res = $this->model->wishLuckPoolConfigChildDel($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACTIVITY, '删除许愿池奖池配置特殊玩法');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

     //许愿池添加投入奖励列表
     public function addWishLuckExGiftList(Request $request){
        $res = $this->model->addWishLuckExGiftList($request->all());

        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池查看投入展示礼物列表
    public function getWishLuckExGiftList(Request $request){
        $res = $this->model->getWishLuckExGiftList($request->all());

        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池新增奖池投入礼物
    public function addExGiftForPool(Request $request){
        $res = $this->model->addExGiftForPool($request->all());

        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //许愿池查看投入记录
    public function getExGiftForPoolList(Request $request){
        $res = $this->model->getExGiftForPoolList($request->all());

        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }
}
